<?php

use yii\helpers\Html;
use kartik\grid\GridView;
use yii\helpers\ArrayHelper;
use kartik\select2\Select2;
use common\models\shop\ShopGoods;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\shop\models\ShopGoodsSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '商品管理';
$this->params['breadcrumbs'][] = $this->title;
?>


<section class="wrapper site-min-height">
    <!-- page start-->
    <section class="panel">
        <header class="panel-heading">
              <?= Html::a('返回','javascript:history.back(-1)'); ?>  <?= Html::encode($this->title) ?>
        </header>
        <div class="panel-body">
            <div class="adv-table editable-table ">
 


<div class="shop-goods-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('添加商品', ['create'], ['class' => 'btn btn-success']) ?>
    </p>


    <?php
    echo GridView::widget([
        'dataProvider'=>$dataProvider,
        'filterModel'=>$searchModel,
        'showPageSummary'=>true,
        'pjax'=>true,
        'striped'=>true,
        'hover'=>true,
        'panel'=>['type'=>'primary', 'heading'=>'商品管理'],
        'containerOptions'=>['style'=>'overflow: auto'], // only set when $responsive = false
        'headerRowOptions'=>['class'=>'kartik-sheet-style'],
        'filterRowOptions'=>['class'=>'kartik-sheet-style'],
        'columns'=>[
            [
                'attribute'=>'goodssn',
                'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                'width'=>'100px',
            ],
            [
                'attribute'=>'cate.name',
                'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                'width'=>'100px',
            ],
            [
                'attribute'=>'title',
                'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                'width'=>'100px',
            ],
            [
                'attribute'=>'costprice',
                'pageSummaryOptions'=>['class'=>'text-right text-warning'],
                'width'=>'100px',
            ],
            [
                'attribute'=>'sales',
                'width'=>'100px',
                'hAlign'=>'right',
//                    'format'=>['decimal', 0],
//                    'pageSummary'=>true
            ],
            [
                'attribute'=>'total',
                'width'=>'100px',
                'hAlign'=>'right',
//                    'format'=>['decimal', 0],
//                    'pageSummary'=>true
            ],
            [
                'attribute'=>'unit',
                'width'=>'80px',
                'hAlign'=>'right',
//                    'format'=>['decimal', 0],
//                    'pageSummary'=>true
            ],
            [
                'attribute'=>'viewcount',
                'width'=>'100px',
                'hAlign'=>'right',
//                    'format'=>['decimal', 0],
//                    'pageSummary'=>true
            ],
            [
                'attribute'=>'weight',
                'width'=>'100px',
                'hAlign'=>'right',
//                    'format'=>['decimal', 0],
//                    'pageSummary'=>true
            ],
            [
                'attribute'=>'status',
                'width'=>'100px',
                'format' => 'raw',
                'hAlign'=>'right',
                'value' => function($model){
                    if($model->status = ShopGoods::STATUS_ACTIVE){
                        return Html::label(ShopGoods::$statues[$model->status],'',['class'=>'btn btn-xs btn-success']);
                    }
                    return Html::label(ShopGoods::$statues[$model->status],'',['class'=>'btn btn-xs btn-default']);
                }
            ],
            [
                'label' => '属性',
                'width'=>'200px',
                'format' => 'raw',
                'hAlign'=>'right',
                'value' => function($model){
                    $html = '';
                    if($model->isnew == ShopGoods::ISNEW){
                        $html .= Html::label(ShopGoods::$isnew[$model->isnew],'',['class'=>'btn btn-xs btn-danger','style'=>'margin-right:5px;']);
                    }
                    if($model->isrecommand == ShopGoods::RECOMMAND){
                        $html .=  Html::label(ShopGoods::$recommand[$model->isrecommand],'',['class'=>'btn btn-xs btn-info','style'=>'margin-right:5px;']);
                    }
                    if($model->ishot == ShopGoods::HOT){
                        $html .=  Html::label(ShopGoods::$ishot[$model->ishot],'',['class'=>'btn btn-xs btn-warning','style'=>'margin-right:5px;']);
                    }
                    if($model->isprebuy == ShopGoods::PREBUY){
                        $html .=  Html::label(ShopGoods::$isprebuy[$model->isprebuy],'',['class'=>'btn btn-xs btn-success','style'=>'margin-right:5px;']);
                    }
                    return $html;
                }
            ],
            [
                'attribute'=>'pig.no',
                'width'=>'150px',
                'hAlign'=>'right',
            ],
            [
                'class' => '\kartik\grid\ActionColumn',
                'deleteOptions' => ['label' => '<i class="glyphicon glyphicon-remove"></i>']
            ],
        ],
        'toolbar'=> [
            Yii::$app->request->get('id') !== null?[
                'content' => Html::button('<i class="glyphicon glyphicon-plus"></i>', ['type'=>'button', 'title'=>'选中归为档案', 'class'=>'btn btn-success', 'id'=>'addpig'])
            ]:'',
            '{export}',
            '{toggleData}',
        ],
        'bordered'=>true,
        'condensed'=>true,
    ]);
    ?>
</div>
</div>
</div>
</section>
</section>





